package com  
{
	import flash.utils.ByteArray;
	/**
	 * ...
	 * @author Michael
	 */
	public class AnalysisTxt 
	{
		
		public function AnalysisTxt() 
		{
			
		}
		
		
		public static function analysis(fileBytes:ByteArray):ByteArray
		{
			var data:String = fileBytes.readUTFBytes(fileBytes.bytesAvailable);
			
			var vector:Array = [];
			//去掉第一行描述
			var descriptions : Array = data.split("\n");
			//字段数组
			var keys : Array = descriptions.shift().split("\t");
			var rows : int = descriptions.length;
			
			for(var i : int = 0; i < rows; i++)
			{
				
				if(StringUtil.trim(descriptions[i]) != "")
				{
					var description : Array = String(descriptions[i]).split("\t");
					var instance:Object = { };
					var keysLen : int = keys.length;
					for(var j : int = 0; j < keysLen; j++)
					{
						var key:String = keys[j];
						instance[key] = description[j];	
					}
					vector[i] = instance;
				}
			}
			
			var byte:ByteArray = new ByteArray();
		
			byte.writeObject(vector);
			byte.position = 0;
			return byte;
		}
	}
}